<?php
class ManageBadContentForm extends Form
{
	function ManageBadContentForm(){
		Form::Form('ManageBadContentForm');		
		CGlobal::$website_title="Quản trị Tin xấu";
		$this->link_css('style/manage_item.css');
		$this->link_css('style/aznet/ui.datepicker.css');		
		$this->link_js('javascript/jquery/ui.datepicker.js');
	}	
	function on_submit(){
		$ids = (isset($_POST['chk_id']))?$_POST['chk_id']:array(); 							
		if(count($ids)>0){						
			for($i=0;$i<count($ids);$i++){
				DB::query('DELETE FROM bad_content WHERE id="'.$ids[$i].'"');
			}				
			Url::redirect_url(Url::build_all(array('chk_id','del_all','cmd','id')));
		}	
	}
	function draw()
	{
		$this->beginForm();	
		global $display;
		$display->add('created_time_from',Url::get('created_time_from'));
		$display->add('created_time_to',Url::get('created_time_to'));	
		$display->add('sender_user_name',Url::get('sender_user_name'));
		$display->add('processed',Url::get('processed'));
		//search theo ngay thang nam
		$created_time_from=0;
		$created_time_to=0;
		if(Url::get('created_time_from')){
			$date_arr = explode('-',Url::get('created_time_from'));
			if(isset($date_arr[0]) && isset($date_arr[1]) && isset($date_arr[2]))
			$created_time_from = mktime(0,0,0,(int)$date_arr[1],(int)$date_arr[0],(int)$date_arr[2]);
		}
		if(Url::get('created_time_to')){
			$date_arr = explode('-',Url::get('created_time_to'));
			
			if(isset($date_arr[0]) && isset($date_arr[1]) && isset($date_arr[2]))
			$created_time_to = mktime(23,59,59,(int)$date_arr[1],(int)$date_arr[0],(int)$date_arr[2]);
		}
		$search_value=' 1 ';
		if($created_time_from){																	
			$search_value .= ' AND time_post >= '.$created_time_from;
		}
		if($created_time_to){																	
			$search_value .= ' AND time_post <= '.$created_time_to;
		}
		// search ô textbox	
		if(Url::get('sender_user_name')!=''){				
			$search_value .= ' AND b.user_name like "%'.Url::get('sender_user_name').'%" ';
		}
		
		if(Url::get('processed')==1){				
			$search_value .= ' AND b.status = 0';
		}
		
		$item_per_page = 50;				
		$sql_count='SELECT COUNT(*) AS total_item FROM `bad_content` AS b WHERE b.type = 1 AND '.$search_value;		
		$total=DB::fetch($sql_count,'total_item',0);		
		$items=array();
		if($total){
			$limit='';
			$paging = AZPagging::pagingSE($limit,$total,$item_per_page,10,'page_no',true,'Phản hồi','Trang');
			$sql = 'SELECT i.name,i.transaction_type,i.category_id, b.id, b.admin_name, b.status, b.type,b.id_item, b.reason,b.user_id,b.user_name, b.note, b.time_post FROM `bad_content` b LEFT JOIN item i ON i.id = b.id_item WHERE b.type = 1 AND '.$search_value.' ORDER BY b.status, b.time_post DESC, b.type ASC '.$limit;
			$result = DB::query($sql);
			
			if($result){
				while ($row=mysql_fetch_assoc($result)){
					$row['content'] = $row['name'];										
					$row['time_post'] = date('d/m/y H:i',$row['time_post']);				
					$row['content_tooltip'] = AZLib::remove_4_js(AZLib::filter_title($row['content']));					
					$row['content'] = AZLib::word_limit($row['content'],12,'...');
					$row['reason_tooltip'] = AZLib::remove_4_js(AZLib::filter_title($row['reason']));
					$row['reason'] = AZLib::word_limit($row['reason'],12,'...');
					$row['note_tooltip'] = AZLib::remove_4_js(AZLib::filter_title($row['note']));
					$row['note'] = AZLib::word_limit($row['note'],12,'...');
					$row['href'] = WEB_DIR.AZRewrite::formatUrl('?page=item_detail&id='.$row['id_item'].'&ebname='.AZLib::safe_title($row['name']));
					$row['del_link'] = Url::build_all(array('chk_id','del_all','cmd','id'),'cmd=delete&id='.$row['id']);
					$items[$row['id']]=$row;
				}				
			}
		}
		else{
			$paging = '';
		}
	
		$display->add('items',$items);		
		$display->add('paging',$paging);		
		$display->output('list');
		$this->endForm();
	}
	
}
?>